package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sgb.kjwl.R;

import java.util.List;

/**
*@author pangyuheng
*@date 2019/7/9
*description:
*/
public class PackersPersonPapersAdapter extends RecyclerView.Adapter<PackersPersonPapersAdapter.MyViewHolder> {
    /**
     * 当前上下文对象
     */
    Context context;
    /**
     * RecyclerView填充Item数据的List对象
     */
    List<String> data;

    public PackersPersonPapersAdapter(Context context,List<String> data){
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public PackersPersonPapersAdapter.MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        //实例化得到Item布局文件的View对象
        View v = View.inflate(context, R.layout.person_papers_layout_item,null);
        //返回MyViewHolder的对象
        return new MyViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull PackersPersonPapersAdapter.MyViewHolder myViewHolder, int i) {
        Glide.with(context).load(data.get(i)).into(myViewHolder.iv);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    /**
     * 继承RecyclerView.ViewHolder抽象类的自定义ViewHolder
     */
    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView iv;
        public MyViewHolder(View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.iv);
        }
    }
}
